﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Planer.Model.Validators.Base;

namespace Planer.Model.Validators
{
    public class FinancicalGoalValidator : Validator<financial_goal>
    {
        public override void Validate(financial_goal FinancicalGoal)
        {
            if (FinancicalGoal == null) throw new ArgumentNullException("FinancicalGoal", NULL_ARGUMENT_MESSAGE);

            NameValidator nameVlidator = new NameValidator();
            nameVlidator.Validate(FinancicalGoal.name);
            if (nameVlidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(nameVlidator.Errors);
            }

            DescriptionValidator descrValidator = new DescriptionValidator();
            descrValidator.Validate(FinancicalGoal.descr);
            if (descrValidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(descrValidator.Errors);
            }

            if (FinancicalGoal.necessary <= 0)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.Add("Недопустимое значение накапливаемой суммы");
            }

            YesNoValidator closedValidator = new YesNoValidator();
            closedValidator.Validate(FinancicalGoal.closed);
            if (closedValidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(closedValidator.Errors);
            }

            YesNoValidator spentValidator = new YesNoValidator();
            spentValidator.Validate(FinancicalGoal.spent);
            if (spentValidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(spentValidator.Errors);
            }
        }
    }
}
